<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="tag" uri="com.sand.myTag" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<c:if test="${tag:allow(userAuth, 301001) && followUp!='是'}">
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" id="btnAdd"> 添加记录 </button>
    </div>
</div>
</c:if>
<div id="addReocrd" style="display: none" class="layui-form layuimini-form">
    <input type="hidden" name="customerId" value="${rid}">
    <div class="layui-form-item">
        <label class="layui-form-label">记录内容</label>
        <div class="layui-input-block">
            <input type="text" name="recordContent" placeholder="请输入内容" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">记录人:</label>
        <div class="layui-input-block">
            <input type="hidden" name="recordId" id="recordId" value="${user.rid}">
            <input type="text" name="recordId1" value="${user.uName}" placeholder="请选择跟进人ID" autocomplete="off" class="layui-input" id="demo3">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">下次跟进:</label>
        <div class="layui-input-block">
            <input type="text" name="nextFollow" id="nextFollow" placeholder="请选择下次跟进时间" lay-verify="date" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<c:forEach items="${recordList}" var="ite">
    <hr/>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" disabled value="${ite.recordContent}" class="layui-input">
            </div>
            <label class="layui-form-label">时间</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" disabled value="${ite.recordTime}" class="layui-input">
            </div>
            <label class="layui-form-label">记录人</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" disabled value="${ite.recordIds}" class="layui-input">
            </div>
            <label class="layui-form-label">下次跟进时间</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" disabled value="${ite.nextFollow}" class="layui-input">
            </div>
        </div>
    </div>
</c:forEach>


<script src="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/layui/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form', 'tableSelect', 'table', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            tableSelect = layui.tableSelect,
            laydate = layui.laydate,
            $ = layui.$;

        laydate.render({
            elem: '#nextFollow'
        });

        tableSelect.render({
            elem: '#demo3',
            searchKey: 'we',
            checkedKey: 'rid',
            table: {
                url: '${pageContext.request.contextPath}/user_queryUserLimit',
                cols: [[
                    {
                        type: 'radio' }
                    ,{
                        field: 'rid',align:'center', width: 80, title: '编号', sort: true }
                    , {
                        field: 'uName',align:'center', title: '姓名', minWidth: 150
                    }
                ]]
            },
            done: function (elem, data) {
                var NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.uName)
                    $("#recordId").val(item.rid)
                })
                elem.val(NEWJSON.join(","))
            }
        })

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url:"${pageContext.request.contextPath}/customer_addRecord",
                type:"post",
                data:"data="+JSON.stringify(data.field),
                dataType:"text",
                success:(rs)=>{
                    if(rs=="OK"){
                        layer.msg("添加成功",{icon:1,time:500},function (){
                            window.location.href="${pageContext.request.contextPath}/customer_queryRecordById?rid=${rid}"
                        })
                    }else{
                        layer.msg("添加失败",{icon:2,time:500})
                    }
                }
            })
            return false;
        });

        $("#btnAdd").click(()=>{
            $("#addReocrd").slideDown();
        })
    });
</script>
</body>
</html>